<template>
	<view>
		<view class="symptoms">
			患者症状：{{symptoms}}
		</view>
		<view class="time">
			记录日期：{{time}}
		</view>
		<view class="test">
			体检记录：
			<textarea v-if="!isPatient" @input="inputChange" :value="tjResult" id="record" :adjust-position="true" auto-height="true" />
			<view v-else>{{tjResult}}</view>
		</view>
		<button v-if="!isPatient" class="commit" @click="commitTo()">提交</button>
	</view>
</template>

<script>
	import { viewtj, addUpdatetj } from '@/api/index.js'
	export default {
		data() {
			return {
				time:'',
				symptoms: "",
				id: '',
				tjResult: '',
				isPatient: false,
				updateId: ''
			}
		},
		onLoad(option) {
			this.isPatient = uni.getStorageSync('user').patient
			this.symptoms = option.symptoms
			this.id = option.id
			this.getData()
			console.log(option)
		},
		methods:{
			getData() {
				viewtj({registrationId: this.id}).then(res => {
					if(res.code !== 200) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
					console.log(res)
					this.tjResult = res.data.item.medicalResults || ''
					this.time= res.data.item.createTime || ''
					this.updateId = res.data.item.id || ''
				})
			},
			commitTo(){
				console.log(this.tjResult)
				if(!this.tjResult) {
					uni.showToast({
						title: '请填写体检结果',
						icon: 'none'
					})
				} else {
					let param = {
						medicalResults: this.tjResult,
						registrationId: this.id
					}
					if(this.updateId) {
						param.id = this.updateId
					}
					addUpdatetj(param).then(res => {
						if(res.code === 200) {
							uni.showToast({
								title: res.message,
								icon: 'none'
							})
							return
						}
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					})
				}
				
			},
			inputChange(e){
				this.tjResult = e.detail.value
			},
		},
		
	}
</script>

<style>
	.symptoms{
		margin-top: 100rpx;
		font-size: 40rpx;
	}
	.time{
		margin-top: 100rpx;
		font-size: 40rpx;
	}
	.test{
		margin-top: 100rpx;
	}
	textarea {
		height: auto;
		width: auto;
		border: 3px solid #550000;
		word-wrap: break-word;
		white-space: pre-wrap;
		font-size: 50rpx;
	}
	.commit{
		height: auto;
		width: 150rpx;
		margin-top: 30rpx;
		color: #0000FF;
	}
</style>
